# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=cborg
pkgname=haskell-cborg
pkgver=0.2.9.0
pkgrel=22
pkgdesc="Concise Binary Object Representation (CBOR)"
url="https://github.com/well-typed/cborg"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-half' 'haskell-primitive')
makedepends=('ghc' 'uusi' 'haskell-aeson' 'haskell-base-orphans' 'haskell-base16-bytestring'
             'haskell-base64-bytestring' 'haskell-quickcheck' 'haskell-scientific' 'haskell-tasty'
             'haskell-tasty-hunit' 'haskell-tasty-quickcheck' 'haskell-vector')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('cc6e8d8a60d6d219c537023c1f618f91b1a886b1163e645d86bf621849530f6a6fa68937ff4dd47da813847eda00e1a05dfdafa17c121e53b9cd65ab6009ffd3')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.txt
}
